home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
L' Effet Pommier 3
/
L'Effet Pommier - Volume 03.iso
/
Programmation
/
PlayerPRO 4.5.1 Dev.Kit
/
Plug-Ins
/
Digital Plugs
/
NoteTrans.c
< prev
next >
Wrap
C/C++ Source or Header
|
1995-09-23
|
3KB
|
156 lines
/* Note Translate */
/* v 1.0 */
/* 1995 by ANR */
// Usage:
// A small example of to use Digital Editor Plugs with a MODAL DIALOG
#include "MAD.h"
#include "PPPlug.h"
#if defined(powerc) || defined(__powerc)
enum {
PlayerPROPlug = kCStackBased
| RESULT_SIZE(SIZE_CODE( sizeof(OSErr)))
| STACK_ROUTINE_PARAMETER(1, SIZE_CODE(sizeof( Pcmd*)))
| STACK_ROUTINE_PARAMETER(2, SIZE_CODE(sizeof( PPInfoPlug*)))
};
ProcInfoType __procinfo = PlayerPROPlug;
#else
#include <A4Stuff.h>
#endif
/** Utils Functions **/
void GetDText (DialogPtr dlog, short item, StringPtr str)
{
Handle itemHandle;
short itemType;
Rect itemRect;
GetDItem (dlog, item, &itemType, &itemHandle, &itemRect);
GetIText (itemHandle, str);
}
void SetDText (DialogPtr dlog, short item, Str255 str)
{
Handle itemHandle;
short itemType;
Rect itemRect;
GetDItem (dlog, item, &itemType, &itemHandle, &itemRect);
SetIText (itemHandle, str);
}
GDHandle TheGDevice:0xCC8;
void AutoPosition( DialogPtr aDia)
{
Point Position, mouse;
Rect ViewRect;
short XSize = (aDia->portRect.right - aDia->portRect.left), YSize = (aDia->portRect.bottom - aDia->portRect.top);
GetMouse( &mouse);
LocalToGlobal( &mouse);
SetRect( &ViewRect, (*TheGDevice)->gdRect.left + 8, (*TheGDevice)->gdRect.top + 43,
(*TheGDevice)->gdRect.right - 8, (*TheGDevice)->gdRect.bottom - 8);
Position.h = mouse.h - XSize/2;
if( Position.h + XSize >= ViewRect.right) Position.h = ViewRect.right - XSize;
else if( Position.h <= ViewRect.left) Position.h = ViewRect.left;
Position.v = mouse.v - YSize/2;
if( Position.v + YSize >= ViewRect.bottom) Position.v = ViewRect.bottom - YSize;
else if( Position.v <= ViewRect.top) Position.v = ViewRect.top;
MoveWindow( aDia, Position.h, Position.v, false);
ShowWindow( aDia);
}
Cmd* GetCmd( short row, short track, Pcmd* myPcmd)
{
if( row < 0) row = 0;
else if( row >= myPcmd->length) row = myPcmd->length -1;
if( track < 0) track = 0;
else if( track >= myPcmd->tracks) track = myPcmd->tracks -1;
return( &(myPcmd->myCmd[ (myPcmd->length * track) + row]));
}
/** Main function **/
OSErr main( Pcmd *myPcmd,
PPInfoPlug *thePPInfoPlug)
{
DialogPtr myDia;
short itemHit;
Str255 tStr;
#ifndef powerc
long oldA4 = SetCurrentA4(); //this call is necessary for strings in 68k code resources
#endif
myDia = GetNewDialog( 128, 0L, (WindowPtr) -1L);
SetPort( myDia);
AutoPosition( myDia);
SetDText( myDia, 3, "\p0");
SelIText( myDia, 3, 0, 200);
do
{
RESTART:
#if defined(powerc) || defined(__powerc)
ModalDialog( thePPInfoPlug->MyDlgFilterUPP, &itemHit);
#else
ModalDialog( (ModalFilterProcPtr) thePPInfoPlug->MyDlgFilterUPP, &itemHit);
#endif
}while( itemHit != 1 && itemHit != 2);
if( itemHit == 1)
{
short track, row;
long trans;
Cmd *myCmd;
GetDText( myDia, 3, tStr); StringToNum( tStr, &trans);
// Check values
if( trans < -96 || trans > 96)
{
SelIText( myDia, 3, 0, 200);
SysBeep( 1);
goto RESTART;
}
for( track = 0; track < myPcmd->tracks; track++)
{
for( row = 0; row < myPcmd->length; row++)
{
myCmd = GetCmd( row, track, myPcmd);
if( myCmd->note != 0xFF) // no notes = 0xFF
{
if( (long) myCmd->note + trans < 0) myCmd->note = 0;
else if( (long) myCmd->note + trans >= 96) myCmd->note = 96-1;
else myCmd->note += trans;
}
}
}
}
DisposDialog( myDia);
#ifndef powerc
SetA4( oldA4);
#endif
return noErr;
}